least squares polynomial fitting algorithm